<template>
  <div class="carts" ref="cartsRef">
    <span>题库</span>
    <span class="num">{{ num }}</span>
  </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue'

const props = defineProps({
  num: {
    type: Number,
    default: 0
  }
})
const emits = defineEmits(['getPosition'])

const cartsRef = ref()
const position = ref({
  left: 0,
  top: 0
})

onMounted(() => {
  position.value.left = cartsRef.value.getBoundingClientRect().left
  position.value.top = cartsRef.value.getBoundingClientRect().top
  emits('getPosition', position.value)
})
</script>



<style scoped lang="scss">
.carts {
  position: fixed;
  background: #646cff;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  padding: 30px 8px;
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
  writing-mode: vertical-rl; /* 文字竖排 */
  text-align: center; /* 文字居中 */
  >span {
    color: #fff;
  }
  .num {
    font-weight: bold;
  }
}
</style>
